package simulation;

import com.mon4cc.cmon.model.predicate.CondFactory;
import com.mon4cc.cmon.model.predicate.NotCond;
import org.jbpt.pm.AndGateway;
import org.jbpt.pm.DataNode;
import org.jbpt.pm.FlowNode;
import org.jbpt.pm.XorGateway;
import org.jbpt.pm.bpmn.*;
import org.jbpt.pm.data.extended.BpmnConditionalControlFlow;
import org.jbpt.pm.data.extended.DataNodeState;
import org.jbpt.pm.data.extended.ICMCondition;

/**
 * @author Ping
 * @date 2022/12/24 10:19
 **/
public class BPMNTestUtil {
    public static StartEvent StartEvent ;
    public static EndEvent EndEvent ;

    public static Bpmn<BpmnControlFlow<FlowNode>, FlowNode> newABpmn() {
        Bpmn<BpmnControlFlow<FlowNode>, FlowNode> bpm  ;
        bpm = new Bpmn<>();
        CondFactory condFactory = new CondFactory() ;
        StartEvent = new StartEvent("start") ;
        EndEvent = new EndEvent("end") ;
        DataNode a_dn = new DataNode("a_d1") ;
        a_dn.setDataNodeState(DataNodeState.EMPTY);
        ICMCondition cond = CondFactory.newAtomCond("x", ICMCondition.ROP_GREATER_THAN, 3.0) ;
        ICMCondition notCond = new NotCond(cond) ;
        BpmnActivity a_t1 = new Task("a_t1") ;
        a_t1.addWriteDocument(a_dn);
        BpmnActivity a_t2 = new Task("a_t2") ;
        BpmnActivity a_t3 = new Task("a_t3") ;
        BpmnActivity b_t2 = new Task("b_t2") ;
        BpmnActivity c_t3 = new Task("c_t3") ;
        c_t3.addReadDocument(a_dn);
        BpmnActivity d_t4 = new Task("d_t4") ;
        BpmnActivity e_t5 = new Task("e_t5") ;
        BpmnActivity f_t6 = new Task("f_t6") ;
        BpmnActivity g_t7 = new Task("g_t7") ;
        BpmnActivity b_t3 = new Task("b_t3") ;

        XorGateway xgw5 = null ;
        XorGateway xgw1 = null ;
        xgw1 = new XorGateway("xgw1") ;
        XorGateway xgw2 = new XorGateway("xgw2") ;
        XorGateway xgw3 = new XorGateway("xgw3") ;
        XorGateway xgw4 = new XorGateway("xgw4") ;
        xgw5 = new XorGateway("xgw5") ;
        XorGateway xgw6 = new XorGateway("xgw6") ;

        AndGateway agw1 = new AndGateway("agw1") ;
        AndGateway agw2 = new AndGateway("agw2") ;
        // adding control flow
        bpm.addControlFlow(StartEvent, a_t1) ;
//        bpm.addControlFlow(a_t1, a_t2) ;
//        bpm.addControlFlow(a_t2, a_t3) ;
        bpm.addControlFlow(a_t1, xgw1) ;
        bpm.addControlFlow(xgw1, agw1) ;
        bpm.addControlFlow(agw1, xgw2) ;
        bpm.addControlFlow(agw1, c_t3) ;
        bpm.addControlFlow(xgw2, b_t3) ;
        bpm.addControlFlow(b_t3, xgw3) ;
        bpm.addControlFlow(xgw2, b_t2) ;
        bpm.addControlFlow(b_t2, xgw3) ;
        bpm.addControlFlow(xgw3, agw2) ;
        bpm.addControlFlow(c_t3, agw2) ;
        bpm.addControlFlow(agw2, d_t4) ;
        bpm.addControlFlow(d_t4, xgw4) ;

        bpm.addControlFlow(xgw4, g_t7) ;
        bpm.addControlFlow(g_t7, xgw1) ;
        bpm.addControlFlow(xgw4, xgw5) ;
        // bpm.addControlFlow(xgw5, e_t5) ;
        bpm.addControlFlow(new BpmnConditionalControlFlow(bpm, xgw5,cond,e_t5)) ;
        //bpm.addControlFlow(xgw5, f_t6) ;
        bpm.addControlFlow(new BpmnConditionalControlFlow(bpm, xgw5,notCond,f_t6)) ;

        bpm.addControlFlow(e_t5, xgw6) ;
        bpm.addControlFlow(f_t6, xgw6) ;
        bpm.addControlFlow(xgw6, EndEvent) ;
        return bpm ;



    }
}
